'use strict';

const Service = require('egg').Service;
const nodemailer = require('nodemailer');
module.exports = class weChatService extends Service {
  async sent(subject, id) {
    const html = `<p>${id}</p>`;
    const transporter = nodemailer.createTransport(this.app.config.mailOptions);
    const mailOptions = {
      from: this.app.config.sendOptions.from,
      to: this.app.config.sendOptions.to,
      subject,
      html,
    };
    return transporter.sendMail(mailOptions).catch(error => {
      this.ctx.logger.error('Message %s sent error: %s', error)
      return error;
    });
  }
};

